package com.i360day.redis.listener.channel;

import com.alibaba.fastjson.annotation.JSONField;

import java.util.UUID;

/**
 * @description: redis消息通道
 * @author: liju.z
 * @create: 2019-09-06 10:31
 **/
public class RedisMessageListenerChannel<T> implements java.io.Serializable {

    private static final long serialVersionUID = 5516075349620653480L;
    //数据包
    private final T message;
    private final String sourceClazzName;
    //是否队列消息
    @JSONField(name = "isQueue")
    private final boolean queue;
    //列队ID
    private String queueId;
    //是否同步，发送消息后，需要等待处理后在执行
    @JSONField(name = "isSynch")
    private boolean synch;

    /**
     * <p> @Author liju.z <p>
     *
     * <p> @Description //TODO 发送普通消息 <p>
     *
     * <p> @Date  13:31 <p>
     *
     * <p> @Param [message] <p>
     *
     * <p> @return [message] <p>
     **/
    public RedisMessageListenerChannel(T message) {
        this(message, false);
    }

    /**
     * <p> @Author liju.z <p>
     *
     * <p> @Description //TODO 发送列队消息 <p>
     *
     * <p> @Date  13:31 <p>
     *
     * <p> @Param [message, isQueue] <p>
     *
     * <p> @return [message, isQueue] <p>
     **/
    public RedisMessageListenerChannel(T message, boolean isQueue) {
        this.message = message;
        this.queue = isQueue;
        this.synch = false;
        this.sourceClazzName = this.getClass().getName();
        this.queueId = UUID.randomUUID().toString();
    }

    public RedisMessageListenerChannel(T message, boolean isQueue, boolean synch) {
        this.message = message;
        this.queue = isQueue;
        this.sourceClazzName = this.getClass().getName();
        this.queueId = UUID.randomUUID().toString();
        this.synch = synch;
    }

    public RedisMessageListenerChannel(T message, boolean isQueue, String queueId) {
        this.message = message;
        this.queue = isQueue;
        this.queueId = queueId;
        this.sourceClazzName = this.getClass().getName();
        this.synch = false;
    }

    public RedisMessageListenerChannel(T message, boolean isQueue, String sourceClazzName, String queueId) {
        this.message = message;
        this.queue = isQueue;
        this.sourceClazzName = sourceClazzName;
        this.queueId = queueId;
        this.synch = false;
    }


    public RedisMessageListenerChannel(T message, boolean isQueue, String sourceClazzName, String queueId, boolean synch) {
        this.message = message;
        this.queue = isQueue;
        this.sourceClazzName = sourceClazzName;
        this.queueId = queueId;
        this.synch = synch;
    }

    public T getMessage() {
        return this.message;
    }

    public boolean isQueue() {
        return queue;
    }

    public String getSourceClazzName() {
        return sourceClazzName;
    }

    public String getQueueId() {
        return queueId;
    }

    public boolean isSynch() {
        return synch;
    }

    @Override
    public String toString() {
        return "RedisMessageListenerChannel{" +
                "message=" + message +
                ", sourceClazzName='" + sourceClazzName + '\'' +
                ", queue=" + queue +
                ", queueId='" + queueId + '\'' +
                ", synch=" + synch +
                '}';
    }
}
